<template>
  <div id="left">
    <el-menu
      :default-active="menuActive"
      class="el-menu-vertical-demo"
      @open="handleOpenLeft"
      @select="handleSelectLeft"
      unique-opened
      @close="handleCloseLeft"
      background-color="#252a2f"
      text-color="#fff"
      active-text-color="#00c1de"
      style="border-top: 1px solid hsla(0,0%,100%,.1);"
    >
      <el-menu-item :index="urlHome">
        <a :href="urlHome">
          <i class="el-icon-menu"></i>
          <span slot="title">首页</span>
        </a>
      </el-menu-item>
      <menu-tree :menus="dataUserMenu"></menu-tree>
    </el-menu>
  </div>
</template>

<script>
import Vue from 'vue'

Vue.component('menu-tree', {
  name: 'menu-tree',
  template: `
    <div>
      <template v-for = "item in menus">
        <el-submenu v-if="item.data.isParent" :index="item.id + ''">
          <template slot="title">
            <i :class="item.data.icon"></i>
            <span>{{ item.name }}</span>
          </template>
          <menu-tree :menus = "item.children"></menu-tree>
        </el-submenu>
        <el-menu-item v-else :index="item.data.url">
          <a :href="item.data.url">
            <i :class="item.data.icon"></i>
            <span slot="title">{{ item.name }}</span>
          </a>
        </el-menu-item>
      </template>
    </div>
  `,
  props: ['menus']
})

export default {
  name: 'AnimLeft',
  props: ['dataUserMenu', 'urlHome', 'menuActive'],
  data() {
    return {}
  },
  methods: {
    handleOpenLeft(key, keyPath) {
      // console.log(key, keyPath);
    },
    handleCloseLeft(key, keyPath) {
      // console.log(key, keyPath);
    },
    handleSelectLeft(key, keyPath) {
      location.href = key
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
</style>
